import {
  Controller,
  Post,
  Body,
  HttpCode,
  HttpStatus,
  Get
} from '@nestjs/common';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { AuthService } from './auth.service';
import { AuthDto } from 'libs/db/src/schemas';
import { Public } from './decorators/public.decorators';
// import { LogoutDto } from './dto/logoutDto';

@Controller('acl/auth')
@ApiTags('用户登入模块')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  /**
   * 权限用户登入
   * @param dto 用户信息
   * @returns
   */
  @Public()
  @Post('login')
  @HttpCode(HttpStatus.OK)
  @ApiOperation({ summary: '用户登入' })
  login(@Body() dto: AuthDto) {
    return this.authService.login(dto);
  }

  @Post('logout')
  @ApiOperation({ summary: '用户注销', description: '通过token获取' })
  logout(@Body() id: string) {
    return this.authService.logout(id);
  }

  @Public()
  @Get('refresh')
  @ApiOperation({ summary: '刷新', description: 'refresh刷新后延长token时间' })
  refresh() {
    return this.authService.refresh();
  }
}
